load("@fbcode_macros//build_defs:build_file_migration.bzl", "fbcode_target", "non_fbcode_target")
load("@fbcode_macros//build_defs:cpp_benchmark.bzl", "cpp_benchmark")
load("@fbcode_macros//build_defs:cpp_library.bzl", "cpp_library")
load("@fbcode_macros//build_defs:cpp_unittest.bzl", "cpp_unittest")
load("@fbsource//tools/build_defs:default_platform_defs.bzl", "ANDROID", "APPLE", "CXX", "FBCODE", "WINDOWS")
load("@fbsource//tools/build_defs:fb_xplat_cxx_library.bzl", "fb_xplat_cxx_library")
load("@fbsource//tools/build_defs:glob_defs.bzl", "subdir_glob")
load("@fbsource//xplat/folly:defs.bzl", "DEFAULT_APPLE_SDKS")

oncall("fbcode_entropy_wardens_folly")

non_fbcode_target(
    _kind = fb_xplat_cxx_library,
    name = "test-headers",
    header_namespace = "",
    exported_headers = subdir_glob(
        [
            ("", "**/*.h"),
        ],
        prefix = "folly/concurrency/test",
    ),
    apple_sdks = DEFAULT_APPLE_SDKS,
    force_static = True,
    platforms = (ANDROID, APPLE, CXX, FBCODE, WINDOWS),
    visibility = ["PUBLIC"],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "barrier_test",
    srcs = ["BarrierTest.cpp"],
    deps = [
        "//folly:random",
        "//folly/futures:barrier",
        "//folly/portability:gtest",
    ],
    external_deps = [
        "glog",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "callback_lifetime_test",
    srcs = ["CallbackLifetimeTest.cpp"],
    deps = [
        ":test_executor",
        "//folly/futures:core",
        "//folly/portability:gtest",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "collect_test",
    srcs = ["CollectTest.cpp"],
    deps = [
        "//folly:default_keep_alive_executor",
        "//folly:random",
        "//folly:small_vector",
        "//folly/executors:cpu_thread_pool_executor",
        "//folly/executors:manual_executor",
        "//folly/futures:core",
        "//folly/portability:gtest",
        "//folly/synchronization:baton",
    ],
    external_deps = [
        ("boost", None, "boost_thread"),
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "context_test",
    srcs = ["ContextTest.cpp"],
    deps = [
        "//folly/futures:core",
        "//folly/portability:gtest",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "core_test",
    srcs = ["CoreTest.cpp"],
    deps = [
        "//folly/futures:core",
        "//folly/futures/detail:core",
        "//folly/portability:gtest",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "ensure_test",
    srcs = ["EnsureTest.cpp"],
    deps = [
        "//folly/futures:core",
        "//folly/portability:gtest",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "filter_test",
    srcs = ["FilterTest.cpp"],
    deps = [
        "//folly/futures:core",
        "//folly/portability:gtest",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "future_splitter_test",
    srcs = ["FutureSplitterTest.cpp"],
    deps = [
        "//folly/executors:manual_executor",
        "//folly/futures:future_splitter",
        "//folly/portability:gtest",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "future_test",
    srcs = ["FutureTest.cpp"],
    deps = [
        "//folly:executor",
        "//folly:memory",
        "//folly:unit",
        "//folly/executors:manual_executor",
        "//folly/futures:core",
        "//folly/json:dynamic",
        "//folly/portability:gtest",
        "//folly/synchronization:baton",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "semi_future_test",
    srcs = ["SemiFutureTest.cpp"],
    deps = [
        "//folly:executor",
        "//folly:memory",
        "//folly:unit",
        "//folly/executors:manual_executor",
        "//folly/futures:core",
        "//folly/io/async:async_base",
        "//folly/json:dynamic",
        "//folly/portability:gtest",
        "//folly/synchronization:baton",
    ],
)

fbcode_target(
    _kind = cpp_benchmark,
    name = "futures_benchmark",
    srcs = ["Benchmark.cpp"],
    headers = [],
    args = [
        "--json",
    ],
    deps = [
        ":test_executor",
        "//folly:benchmark",
        "//folly/executors:inline_executor",
        "//folly/futures:core",
        "//folly/portability:gflags",
        "//folly/synchronization:baton",
        "//folly/synchronization:native_semaphore",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "header_compile_test",
    srcs = ["HeaderCompileTest.cpp"],
    deps = [
        "//folly:try",
        "//folly/futures:core",
        "//folly/portability:gtest",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "interrupt_test",
    srcs = ["InterruptTest.cpp"],
    labels = ["load-sensitive-timing-test"],
    deps = [
        ":test_executor",
        "//folly/futures:core",
        "//folly/portability:gtest",
        "//folly/synchronization:baton",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "manual_timekeeper_test",
    srcs = ["ManualTimekeeperTest.cpp"],
    deps = [
        "//folly/futures:manual_timekeeper",
        "//folly/portability:gtest",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "map_test",
    srcs = ["MapTest.cpp"],
    deps = [
        "//folly/futures:core",
        "//folly/portability:gtest",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "non_copyable_lambda_test",
    srcs = ["NonCopyableLambdaTest.cpp"],
    deps = [
        "//folly/futures:core",
        "//folly/portability:gtest",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "poll_test",
    srcs = ["PollTest.cpp"],
    deps = [
        "//folly/futures:core",
        "//folly/portability:gtest",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "promise_test",
    srcs = ["PromiseTest.cpp"],
    deps = [
        "//folly/futures:core",
        "//folly/portability:gtest",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "reduce_test",
    srcs = ["ReduceTest.cpp"],
    deps = [
        "//folly/futures:core",
        "//folly/portability:gtest",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "retrying_test",
    srcs = ["RetryingTest.cpp"],
    deps = [
        ":test_executor",
        "//folly/futures:core",
        "//folly/portability:gtest",
        "//folly/portability:sys_resource",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "self_destruct_test",
    srcs = ["SelfDestructTest.cpp"],
    deps = [
        "//folly/executors:inline_executor",
        "//folly/futures:core",
        "//folly/portability:gtest",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "shared_promise_test",
    srcs = ["SharedPromiseTest.cpp"],
    deps = [
        "//folly/futures:shared_promise",
        "//folly/portability:gtest",
    ],
)

fbcode_target(
    _kind = cpp_library,
    name = "test_executor",
    srcs = ["TestExecutor.cpp"],
    headers = ["TestExecutor.h"],
    exported_deps = [
        "//folly:executor",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "test_executor_test",
    srcs = ["TestExecutorTest.cpp"],
    deps = [
        ":test_executor",
        "//folly/portability:gtest",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "then_compile_test",
    srcs = ["ThenCompileTest.cpp"],
    headers = ["ThenCompileTest.h"],
    deps = [
        "//folly/futures:core",
        "//folly/portability:gtest",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "then_test",
    srcs = ["ThenTest.cpp"],
    deps = [
        "//folly/futures:core",
        "//folly/portability:gtest",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "timekeeper_test",
    srcs = ["TimekeeperTest.cpp"],
    deps = [
        "//folly:singleton",
        "//folly/futures:core",
        "//folly/portability:gtest",
    ],
)

fbcode_target(
    _kind = cpp_library,
    name = "timekeeper_test_lib",
    headers = ["TimekeeperTestLib.h"],
    exported_deps = [
        "fbsource//third-party/fmt:fmt",
        "//folly:default_keep_alive_executor",
        "//folly:random",
        "//folly:singleton",
        "//folly/executors:global_executor",
        "//folly/executors:manual_executor",
        "//folly/executors:serial_executor",
        "//folly/executors:virtual_executor",
        "//folly/futures:core",
        "//folly/portability:gtest",
    ],
    exported_external_deps = [
        "glog",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "thread_wheel_timekeeper_test",
    srcs = ["ThreadWheelTimekeeperTest.cpp"],
    supports_static_listing = False,
    deps = [
        ":timekeeper_test_lib",
        "//folly/futures:core",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "heap_timekeeper_test",
    srcs = ["HeapTimekeeperTest.cpp"],
    supports_static_listing = False,
    deps = [
        ":timekeeper_test_lib",
        "//folly/futures:core",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "times_test",
    srcs = ["TimesTest.cpp"],
    deps = [
        "//folly/executors:manual_executor",
        "//folly/futures:core",
        "//folly/portability:gtest",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "unwrap_test",
    srcs = ["UnwrapTest.cpp"],
    deps = [
        "//folly/futures:core",
        "//folly/portability:gtest",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "via_test",
    srcs = ["ViaTest.cpp"],
    deps = [
        "//folly:mpmc_queue",
        "//folly/executors:drivable_executor",
        "//folly/executors:inline_executor",
        "//folly/executors:manual_executor",
        "//folly/futures:core",
        "//folly/portability:gtest",
        "//folly/synchronization:baton",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "wait_test",
    srcs = ["WaitTest.cpp"],
    deps = [
        ":test_executor",
        "//folly/executors:inline_executor",
        "//folly/futures:core",
        "//folly/io/async:async_base",
        "//folly/portability:gtest",
        "//folly/synchronization:baton",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "when_test",
    srcs = ["WhenTest.cpp"],
    deps = [
        "//folly/futures:core",
        "//folly/portability:gtest",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "while_do_test",
    srcs = ["WhileDoTest.cpp"],
    deps = [
        "//folly/executors:manual_executor",
        "//folly/futures:core",
        "//folly/portability:gtest",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "will_equal_test",
    srcs = ["WillEqualTest.cpp"],
    deps = [
        "//folly/futures:core",
        "//folly/portability:gtest",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "window_test",
    srcs = ["WindowTest.cpp"],
    deps = [
        "//folly:conv",
        "//folly/executors:manual_executor",
        "//folly/futures:core",
        "//folly/portability:gtest",
    ],
    external_deps = [
        ("boost", None, "boost_thread"),
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "conversion_operator",
    srcs = ["ConversionOperatorTest.cpp"],
    deps = [
        "//folly/futures:core",
        "//folly/portability:gtest",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "cleanup_test",
    srcs = ["CleanupTest.cpp"],
    headers = [],
    labels = ["case-isolation-failure"],
    deps = [
        "//folly/executors:cpu_thread_pool_executor",
        "//folly/executors:manual_executor",
        "//folly/futures:cleanup",
        "//folly/portability:gtest",
    ],
)
